﻿using System;
using System.Windows.Forms;
using xfsale.lib;

namespace xfsale.ui.acct
{
    public partial class FrmBase2 : FrmBase
    {
        public FrmBase2()
        {
            InitializeComponent();
        }

        protected void ChangeTransAccountID(TextBox TxtTransAccountID)
        {
            String transAccountID = TxtTransAccountID.Text;
            if (string.IsNullOrEmpty(transAccountID))
                return;

            transAccountID = transAccountID.Trim();
            if (string.IsNullOrEmpty(transAccountID))
                return;

            TransAccount account = Query.GetTransAccount(transAccountID);
            if (account == null)
            {
                TxtCustName.Text = string.Empty;
                TxtCertNo.Text = string.Empty;
                RadCustTypeIndi.Checked = true;
                TxtTransAccountID.Text = string.Empty;
                TxtTransAccountID.Focus();
                SysMessage.Error("交易帐号不存在");
                return;
            }

            if (account.CustType == "0")
                InitCtrl(CmbCertType, "InstCertType");
            else if (account.CustType == "1")
                InitCtrl(CmbCertType, "IndiCertType");

            TxtCustName.Text = account.CustName;
            TxtCertNo.Text = account.CertNo;
            RadCustTypeIndi.Checked = account.CustType == "1";
            RadCustTypeInst.Checked = account.CustType == "0";
        }

        protected void SubmitForm()
        {
            string password = null;
            if (!InputPassword(out password))
            {
                return;
            }

            try
            {
                SetProcParamIn("TradePassword", password);

                //BindProcParamsIn();
                CallProc();
                //BindProcParamsOut();

                if (returnCode == "0000")
                {
                    //string orderSerialNo = GetProcParamOut("OrderSerialNo");
                    string orderSerialNo = GetProcParamOut("OrderSerialNo");
                    SysMessage.Info("{0} 委托流水号: {1}", returnMsg, orderSerialNo);
                }
                else
                {
                    SysMessage.Error("ERR-{0} {1}", returnCode, returnMsg);
                }
            }
            catch (Exception ex)
            {
                SysMessage.Error(ex.Message);
            }
        }
    }
}
